<template>
  <el-card class="category-card">
    <el-form :model="cStore" inline>
      <el-form-item label="一级分类" prop="category1Id">
        <el-select v-model="cStore.c1Id" clearable @change="changeC1">
          <el-option
            v-for="item in cStore.c1Arr"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" prop="category2Id">
        <el-select v-model="cStore.c2Id" clearable @change="changeC2">
          <el-option
            v-for="item in cStore.c2Arr"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" prop="category3Id">
        <el-select v-model="cStore.c3Id" clearable>
          <el-option
            v-for="item in cStore.c3Arr"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import useCategoryStore from '@/store/modules/category'
const cStore = useCategoryStore()

onMounted(() => {
  cStore.getCategory1Fun()
})
const changeC1 = (val: number) => {
  cStore.c2Arr = []
  cStore.c3Arr = []
  cStore.c2Id = ''
  cStore.c3Id = ''
  val && cStore.getCategory2Fun(val)
}
const changeC2 = (val: number) => {
  cStore.c3Arr = []
  cStore.c3Id = ''

  val && cStore.getCategory3Fun(val)
}
</script>

<style lang="scss" scoped></style>
